
function [tau0Vec , x0Mtx , sigmaMtx] = Bcr4bp_RandDI2D(coord , orbNum , dvBound , aux)
%
% 随机生成 DRO Injection 状态，2D
%
% 例：
% Bcr4bp_RandLI2D('emrot' , 500 , [0.65 , 0.65] , aux);
%
% 20220926
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 预分配
tau0Vec = zeros(orbNum , 1);
x0Mtx = zeros(orbNum , 4);
sigmaMtx = zeros(orbNum , 1);

% 循环orbNum
for iLoop = 1 : orbNum

    % 随机太阳相位角
    thetas = unifrnd(0 , 2 * pi);
    tauf = thetas / aux.EMRot.ws;

    % 随机相位角和脉冲
    sigma = unifrnd(0 , 1);

    % DRO入轨点脉冲 (VU)
    dvMag = unifrnd(dvBound(1) , dvBound(2) , 1);

    % dro入轨点状态 (LU , VU)
    periOrb_x = interp1(aux.periOrb_tt , aux.periOrb_xx , sigma * aux.periOrb_P , 'spline')';
    x_dro = periOrb_x(1);
    y_dro = periOrb_x(2);
    vx_dro = periOrb_x(3);
    vy_dro = periOrb_x(4);

    % 计算卫星入轨状态
    xx_rot = [x_dro;
        y_dro;
        vx_dro + dvMag * vx_dro / sqrt(vx_dro^2 + vy_dro^2);
        vy_dro + dvMag * vy_dro / sqrt(vx_dro^2 + vy_dro^2)];

    if strcmp(coord , 'emrot')

        tau0Vec(iLoop , :) = tauf;
        x0Mtx(iLoop , :) = xx_rot;
        sigmaMtx(iLoop , :) = sigma;

    elseif strcmp(coord , 'sb1rot')

        % EMRot -> SB1Rot
        [tau_SB1Rot , xb2c_SB1Rot] = Bcr4bp_EMRot2SB1Rot2D(tauf , xx_rot , aux);

        tau0Vec(iLoop , :) = tau_SB1Rot;
        x0Mtx(iLoop , :) = xb2c_SB1Rot;
        sigmaMtx(iLoop , :) = sigma;

    else

        fprintf('wrong!')
        tau0Vec = [];
        x0Mtx = [];
        return;

    end

end



end
